import "https://cdn.bootcdn.net/ajax/libs/jquery/1.12.4/jquery.min.js"; //引入第三方的类库
function login() {
    //思路 获取元素对象  确认手机号是否存在 后端返回结果
    const tel = $('.telnumber');
    const password = $('.password');
    const checkspan = $('.checkspan');
    const btn = $('.btn');
    let telflag = true;
    tel.on('blur', function() {
        $.ajax({
            type: 'post',
            url: 'http://10.31.155.14:81/2104_me/nike/php/login.php',
            data: {
                telnumber: $(this).val()
            }
        }).done(function(data) {
            if (data === 'false') {
                checkspan.eq(0).css('color', 'red').html('手机号不存在');
                telflag = false;
            } else {
                checkspan.eq(0).html('');
                telflag = true;
            }
        });
    });
    btn.on('click', function() {
        if (telflag) {
            $.ajax({
                type: 'post',
                url: 'http://10.31.155.14:81/2104_me/nike/php/login.php',
                data: {
                    telnumber: tel.val(),
                    pass: password.val(),
                }
            }).done(function(data) {
                if (data === 'success') {
                    location.href = 'index1.html';
                    localStorage.setItem('telnumber', tel.val());

                } else {
                    if (data === 'passwordfail') {
                        checkspan.eq(1).css('color', 'red').html('密码错误');
                    } else {
                        checkspan.eq(1).html('');
                    }
                }
            });
        }
    });
}

export {
    login
}